<?php

class adminbase extends CI_Controller {

    //-- init base variable
    protected $arrRuleTp = array();
    protected $strMenuCd;

    public function __construct() {
        //-- clear cache
        $this->clearCache();
        //-- load basic controller
        parent::__construct();
        if ($this->session->userdata('session_admin') == FALSE) {
            redirect('login/loginadmin');
        }
        //-- load app data
        $this->baseLoadApp();
        //-- load view app data
        $this->baseViewApp();
    }

    /*
     * Method pengolah base load
     * diperbolehkan untuk dioverride pada class anaknya
     */

    protected function baseLoadApp() {
        //-- load themes (themes default : default)
        $this->smarty->load_themes("default-admin");
        //-- load base models
        //-- load javascript
        $this->smarty->load_javascript("resource/js/jquery/jquery-1.4.2.min.js");
        $this->smarty->load_javascript("resource/js/jquery.custom/jquery-ui-1.8.16.custom.min.js");
        $this->smarty->load_javascript("resource/js/jquery.custom/jquery.tabs.js");
        $this->smarty->load_javascript("resource/js/jquery.treeview/jquery.treeview.js");
        $this->smarty->load_javascript("resource/js/jquery.dropdown/dropdown.menu.js");
        $this->smarty->load_javascript("resource/js/jquery.treeview/lib/jquery.cookie.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.effects.core.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.button.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.core.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.dialog.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.draggable.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.position.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.resizable.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.widget.js");
        $this->smarty->load_javascript("resource/js/jquery.ui/jquery.ui.mouse.js");
        //-- load style
        //-- assign var
        $arrSessData = $this->session->userdata("session_admin");
       
        $this->smarty->assign("strUsername", $arrSessData['username']);
        $this->smarty->assign("strUserStatus", $arrSessData['status']);
    }

    /*
     * Method pengolah base view
     * diperbolehkan untuk dioverride pada class anaknya
     */

    protected function baseViewApp() {
        $this->smarty->assign("arrConfig", $this->config);
        //-- display global link
        self::displayBaseLink();
        //-- display site title
        self::displaySiteTitle();
        //-- display top navigation
        self::displayBreadcrumbNavigation();
        //-- display sidebar navigation
       
    }
    /*
     * Method layouting base document
     * diperbolehkan untuk dioverride pada class anaknya
     */

    protected function display($pStrTemplateName = 'base/admin/index.html') {
        // --assign template
        $this->smarty->assign("strTemplateHeader", "base/admin/header.html");
        $this->smarty->assign("strTemplateSidebar", "base/admin/sidebar.html");
        //-- set template
        $this->smarty->display($pStrTemplateName);
    }

    //--display base link
    private function displayBaseLink() {
        //-- set url logout
        $this->smarty->assign("strUrlLogout", site_url("login/loginadmin/logoutProcess"));
    }

    //--set site title
    private function displaySiteTitle() {
        $this->smarty->assign("strPageTitle", "CiSmart | Time Excelindo PHP Framework");
    }

    // top navigation
    private function displayBreadcrumbNavigation() {
        //-- set breadcrumb url
        $strHtmlBreadcrumb = "<a href='" . base_url() . "index.php/home/welcomeadmin'>Home</a>";
        $this->smarty->assign("strBreadcrumbUrl", $strHtmlBreadcrumb);
    }
    //-- set page rule
//    protected function setPageRule($pStrRule) {
//        if (!isset($this->arrRuleTp[$pStrRule]) || $this->arrRuleTp[$pStrRule] != '1') {
//            redirect('home/adminforbidden');
//        }
//    }

    //-- clear login cache
    protected function clearCache() {
        header('Cache-Control: no-store, no-cache, must-revalidate');
        header('Cache-Control: post-check=0, pre-check=0', false);
        header('Pragma: no-cache');
    }
}